[SPARK-20121][SQL] simplify NullPropagation with NullIntolerant#17450
[SPARK-20121][SQL] simplify NullPropagation with NullIntolerant#17450cloud-fan wants to merge 2 commits intoapache:masterfrom
Conversation
|
cc @gatorsmile |
|
Test build #75298 has started for PR 17450 at commit |
|
retest this please |
|
Test build #75318 has finished for PR 17450 at commit
|
| // scalastyle:on line.size.limit | ||
| case class Substring(str: Expression, pos: Expression, len: Expression) | ||
| extends TernaryExpression with ImplicitCastInputTypes { | ||
| extends TernaryExpression with ImplicitCastInputTypes with NullIntolerant { |
There was a problem hiding this comment.
Is the function SUBSTRING null-intolerant? What is the return value if str is a null value?
There was a problem hiding this comment.
The result can be null; if any argument is null, the result is the null value.
Ref: https://www.ibm.com/support/knowledgecenter/en/SSEPEK_10.0.0/sqlref/src/tpc/db2z_bif_substr.html
There was a problem hiding this comment.
I might be confused with the terminologies: NullIntolerant expression versus "null-intolerant predicate". But if SUBSTRING is marked null-intolerant expression, why do we not mark the class of string functions such as STARTSWITH, etc. the same way? Am I missing anything here?
There was a problem hiding this comment.
Yes, we should mark NullIntolerant to the other expressions, if possible, and also update the document.
There was a problem hiding this comment.
@nsyca If you have a bandwidth, could you please review all the expressions and see whether they can be marked as NullIntolerant?
You can check the impl of these expressions and compare them with the corresponding ones in the other RDBMS. Thanks!
Below is a ref PR you can use: https://github.com/apache/spark/pull/15850/files. You can continue my work if you want.
There was a problem hiding this comment.
I will certainly take a look. On a second thought, since "most" of the SQL functions are null-intolerant, isn't easier to mark only functions that are null-tolerant such as ISNOTNULL? I am just pitching an idea here, not indicating we should abandon this PR.
There was a problem hiding this comment.
At the beginning, when we introduce NullIntolerant , @marmbrus said we should do it more carefully. We prefer to using the white-list solution for avoiding hidden bugs. Marking it NullIntolerant if and only if we are ensure that they are null intolerant. Thus, when we doing it, we should also add the corresponding test cases and documents.
| // Literal(null) | ||
| case In(Literal(null, _), list) => Literal.create(null, BooleanType) | ||
|
|
||
| // Put exceptional cases above if any |
There was a problem hiding this comment.
Nit: Attribute is also NullIntolerant Maybe add a comment?
Non-leaf NullIntolerant expressions will return null, if at least one of its children is a null literal.
|
Great! LGTM except a minor comment. |
| trait StringPredicate extends Predicate with ImplicitCastInputTypes { | ||
| self: BinaryExpression => | ||
| abstract class StringPredicate extends BinaryExpression | ||
| with Predicate with ImplicitCastInputTypes { |
There was a problem hiding this comment.
Missing with NullIntolerant here?
There was a problem hiding this comment.
This PR is just to simplify the existing rule NullPropagation.
There was a problem hiding this comment.
See above StringRegexExpression, similar to it, in order to simplify the NullPropagation, we need to add NullIntolerant, so it can propagate null value...
There was a problem hiding this comment.
I finally got your point. StringPredicate is used for inferring the null constants in the rule NullPropagation. Thus, we should mark it as NullIntolerant .
|
LGTM |
|
Test build #75390 has finished for PR 17450 at commit
|
|
retest this please |
|
Test build #75392 has finished for PR 17450 at commit
|
|
Thanks! Merging to master. |
What changes were proposed in this pull request?
Instead of iterating all expressions that can return null for null inputs, we can just check
NullIntolerant.How was this patch tested?
existing tests